package com.example.fw;


public class ContactHelper extends HelpersBase{

	private static final int timeForActivation = 5000;

	public ContactHelper(ApplicationManager applicationManager) {
		super(applicationManager);
	}

	public void createContact(Contact contact) {
	initContactCreation();
	fillContactForm(contact);
	confirmContactCreation();
	}

	private void confirmContactCreation() {
		manager.getAutoItHelper()
		.click("Save")
		.winWaitAndActivate("AddressBook Portable", "", timeForActivation);
	}

	private void fillContactForm(Contact contact) {
	
		manager.getAutoItHelper()
			.send("TDBEdit12", contact.firstname)
			.send("TDBEdit11", contact.lastname);
	}

	private void initContactCreation() {
		manager.getAutoItHelper()
			.winWaitAndActivate("AddressBook Portable", "", 5000)
			.click("Add").winWaitAndActivate("Add Contact", "", 5000);
	}

	public Contact getFirstContact() {
		manager.getAutoItHelper()
		.winWaitAndActivate("AddressBook Portable", "", 5000)
		.click("TListView1")
		.send("{DOWN}{SPACE}")
		.click ("Edit")
		.winWaitAndActivate("Update Contact", "", 5000);
		Contact contact = new Contact().
		setFirstName(manager.getAutoItHelper().getText("TDBEdit12"))
		.setLastName(manager.getAutoItHelper().getText("TDBEdit11"));
		manager.getAutoItHelper().click("Cancel");
		return contact;
	}

	public void deleteContact() {
		System.out.println("START");
		getFirstContactInTable();
		manager.getAutoItHelper()
		.click("TRbButton2");
		System.out.println("CONFIRM");
		manager.getAutoItHelper()
		.click("TButton2");
		System.out.println("CONFIRMED");
	}

	private AutoItHelper getFirstContactInTable() {
		return manager.getAutoItHelper()
		.winWaitAndActivate("AddressBook Portable", "", 5000)
		.click("TListView1")
		.send("{DOWN}{SPACE}");
		}

}
